package com.sc.page;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sc.bean.GoodsBean;
import com.sc.data.GoodsData;

public class AddScart extends HttpServlet {

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		//fix
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		String path = req.getContextPath();
		resp.setContentType("text/html");
		
		String id = req.getParameter("id");
		GoodsData gd = GoodsData.getInstance();
		GoodsBean g = gd.getById(Long.parseLong(id));
		
		
		
		HttpSession s = req.getSession();
		List<GoodsBean> sc = (List<GoodsBean>) s.getAttribute("sc");
		if(sc==null){
			sc = new ArrayList<GoodsBean>();
		}
		
		
		
		sc.add(g);
		s.setAttribute("sc", sc);
		
		
		//req
		
		//resp
		resp.sendRedirect(path+"/goods.html");
	}

}
